package com.atguigu.chapter05.transform;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Author: Pepsi
 * Date: 2023/7/28
 * Desc:
 */
public class Flink07_shuffle {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);

        DataStreamSource<Integer> sour = env.fromElements(4, 7, 2, 99, 57, 34, 67);
        // 将数据随机打乱
//        DataStream<Integer> res = sour.shuffle();  // ShufflePartitioner 用随机数生成的
//        DataStream<Integer> res = sour.rebalance();  // RebalancePartitioner 类似轮询，一个一个分配  可能存在跨taskmanager，所以效率不高
        DataStream<Integer> res = sour.rescale();   // RescalePartitioner 效率比较高
        res.print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
